package com.zyf.common.util;

import com.zyf.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/** 获取用户信息的工具类
 * @author zyf
 * @date 2021年05月21日 17:41
 */
public class AuthContextHolder {

    //获取用户的id
    public static Long getUserId(HttpServletRequest request){
        //从header中获取token
        String token = request.getHeader("token");
        //用jwt工具类获取userId
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    //获取用户名称
    public static String getUserName(HttpServletRequest request){
        //从header中获取token
        String token = request.getHeader("token");
        //用jwt工具类获取userId
        String userName = JwtHelper.getUserName(token);
        return userName;
    }
}
